package com.qzd.prototype;

import com.qzd.prototype.deep.ConcretePrototy;

import java.util.ArrayList;
import java.util.List;

public class Test {
    /**
     * 原型模式就是不通过一个new创建对象，而是通过方法来创建一个值相同的对象
     * @param args
     */
    public static void main(String[] args) {
        ConcretePrototy c=new ConcretePrototy();
        c.setAge(4);
        c.setName("anny");
        List<String> list=new ArrayList<String>();
        list.add("aaq");
        list.add("bb0");
        c.setSlist(list);

        //拷贝原型对象
        /*ConcretePrototy clone = c.clone();
        clone.getSlist().add("ccc");
        System.out.println(c.toString());
        System.out.println(clone.toString());*/
        try {
            ConcretePrototy deepclone = c.deepclone();
            deepclone.getSlist().add("ccc");
            System.out.println(c.toString());
            System.out.println(deepclone.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
